import { notFound } from "next/navigation"; import { sql } from "@/db"; import { requireUserPage } from "@/lib/auth/guard"; import { csrfToken } from "@/lib/auth/session"; import { ingestAction } from "@/lib/admin/actions"; import { Csrf, Field, Notice, PageTitle, Select } from "@/components/admin-ui"; export default async function Candidate({ params, searchParams }: { params: Promise<{ id: string }>; searchParams: Promise> }) { const { id } = await params; const sp = await searchParams; const u = await requireUserPage(); const csrf = csrfToken(u); const [c] = await sql`SELECT c.*, f.pages, f.integrity_ok, f.pdf_meta, f.sha256 AS fsha FROM ingest_candidates c LEFT JOIN files f ON f.id = c.file_id WHERE c.id = ${id}`; if (!c) notFound(); const pr = (c.proposal ?? {}) as Record; const [authors, series, papers] = await Promise.all([sql`SELECT id, display_name FROM authors ORDER BY sort`, sql`SELECT code, name_en FROM series ORDER BY sort`, sql`SELECT id, identifier, title FROM papers ORDER BY number DESC`]); const guessAuthors = new Set((authors as unknown as { id: number; display_name: string }[]).filter((a) => (pr.authors ?? []).some((n: string) => n.toLowerCase().includes(a.display_name.split(" ").pop()!.toLowerCase()))).map((a) => a.id)); const MONTH: Record = { january: 1, february: 2, march: 3, april: 4, may: 5, june: 6, july: 7, august: 8, september: 9, october: 10, november: 11, december: 12, janvier: 1, février: 2, mars: 3, avril: 4, mai: 5, juin: 6, juillet: 7, août: 8, septembre: 9, octobre: 10, novembre: 11, décembre: 12 }; const dm = pr.dateText ? /^(\S+)\s+(\d{4})$/.exec(pr.dateText) : null; const dateGuess = dm && MONTH[dm[1].toLowerCase()] ? `${dm[2]}-${String(MONTH[dm[1].toLowerCase()]).padStart(2, "0")}` : ""; return (

Extraction report {c.status}

SHA-256
{c.sha256}
Integrity
{c.integrity_ok === null ? "pending" : c.integrity_ok ? "OK" : FAILED} · {c.pages ?? "?"} pages
PDF metadata
{pr.pdfMeta ? `${pr.pdfMeta.title ?? "—"} / ${pr.pdfMeta.author ?? "—"} / ${pr.pdfMeta.creationDate ?? "—"}` : "—"}
Confidence
{pr.confidence ? Object.entries(pr.confidence).map(([k, v]) => `${k}:${Number(v).toFixed(1)}`).join(" ") : "—"}
{(c.flags as { code: string; message: string }[]).length > 0 &&
    {(c.flags as { code: string; message: string }[]).map((f) =>
  • ⚠ {f.message}
  • )}
} {(c.duplicates as { identifier: string; title: string; reasons: string[]; score: number; paperId: string }[]).length > 0 &&

Possible duplicates

    {(c.duplicates as { identifier: string; title: string; reasons: string[]; score: number }[]).map((d) =>
  • {d.identifier} {d.title} — {d.reasons.join(", ")} ({(d.score * 100).toFixed(0)}%)
  • )}
} {pr.abstract &&
Proposed abstract

{pr.abstract}

}

The proposal below is a suggestion extracted from the title page. Verify every field against the manuscript. The release date must come from the document, never from the file timestamp. Author consent to publication is not inferred.

{c.status === "ready" && c.integrity_ok && (<>

Approve as a new working paper (draft)

{a.display_name})}

Unknown authors must first be created in Taxonomy.

Attach as a new version of an existing paper

Make it the current version (re-indexes full text) )}
); }